/**
 * 
 */
package com.google.code.maven.plugin.http.client.config;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.maven.project.MavenProject;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.expression.StandardBeanExpressionResolver;
import org.springframework.util.Assert;

/**
 * ProjectEvaluationContext
 * 
 * @author Nadim Benabdenbi
 * @version 1.0
 * @since JDK1.6
 */
public class ConfigurationContext {

	protected static final AtomicInteger id = new AtomicInteger();

	/**
	 * the bean factory
	 */
	private final DefaultListableBeanFactory beanFactory;

	/**
	 * default constructor
	 */
	public ConfigurationContext(MavenProject project) {
		super();
		Assert.notNull(project, "project can not be null");
		beanFactory = new DefaultListableBeanFactory();
		beanFactory.registerSingleton("project", project);
		beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver());
	}

	public void registerConfigFactory(ConfigurationBean<?> bean) {
		beanFactory.registerSingleton(Integer.toString(id.incrementAndGet()), bean);
	}

	/**
	 * @return the beanFactory
	 */
	public DefaultListableBeanFactory getBeanFactory() {
		return beanFactory;
	}

}
